package Thread;

import javax.swing.border.BevelBorder;
import java.util.Random;

public class HW1 {
    public static void main(String[] args) throws InterruptedException {
    int[] arr=new int[10000000];
    Random random=new Random();
    long start=System.currentTimeMillis();
    for (int i = 0; i < 10000000; i++) {
        arr[i]=random.nextInt(100)+1;
    }
    sumTask even=new sumTask(arr,true);
    sumTask odd=new sumTask(arr,false);
    Thread evenThread=new Thread(even);
    Thread oddThread=new Thread(odd);
    evenThread.start();
    oddThread.start();
    evenThread.join();
    oddThread.join();
    long end=System.currentTimeMillis();
    System.out.println(end-start);
        System.out.println(even.getSum());
    }
    static class sumTask implements Runnable{
        private int[] arr;
        private boolean isEvenIndex;
        private long sum;
        public   sumTask(int[] arr, boolean isEvenIndex) {
            this.arr=arr;
            this.isEvenIndex=isEvenIndex;
        }

        @Override
        public void run() {
        sum=0;
        int start=isEvenIndex?0:1;
        for(int i=start; i<arr.length; i+=2){
            sum+=arr[i];
        }
        }
        public long getSum() {
            return sum;
        }
    }
}